/**
 * 
 */
$.extend({
	removeFriend : function(friendId) {
		url = 'index.php?remove&type=friend&friendId=' + friendId;
		$.get(url, function(data){
			if (data == 1) {
				alert('Xóa bạn khỏi danh sách thành công');
				$('#profileInformation').load('index.php?load&view=profileInformation&userid=' + friendId);
			} else {
				alert('Xóa bạn khỏi danh sách không thành công');
			}
		});
	},
	sendMessage:function(receiverId) {
		$('#frmSendMess input[name=receiver]').val(receiverId);
		$('#dlgSendMessage').dialog('open');	
	},
	makeFriend:function(userId) {
		var url = "index.php?add&type=friend&userid=" + userId;
		
		$.post(url, function(data) {
			alert('Gửi tin nhắn kết bạn thành công');
		});
	},
//	
//	getUrlVars: function(){
//	    var vars = [], hash;
//	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
//	    for(var i = 0; i < hashes.length; i++) {
//	      hash = hashes[i].split('=');
//	      vars.push(hash[0]);
//	      vars[hash[0]] = hash[1];
//	    }
//	    return vars;
//	},
//	
//	getUrlVar: function(name){
//	    return $.getUrlVars()[name];
//	},
	
	plusComment : function (id) {
			alert('plusComment');
			var url = "index.php?comment&action=plus"
			$.post(url, 
					{commentID: pid}, 
					function(data) {
						alert(data);
					}
				);
	},
	
	minusComment : function (id) {
		alert('minusComment');
		var url = "index.php?comment&action=minus"
		$.post(url, 
				{commentID: pid}, 
				function(data) {
					alert(data);
				}
		);
	}/*,
	
	addLocationToComboBox : function() {
		$('#selCity').change(function() {
			url = 'index.php?location&action=get';
			var pid = $('#selCity').val();
			 
			$.post(url, 
				{parentID: pid}, 
				function(xml) {
					var str = $.getXMLStringOf(xml, 'location');
					str = '<option value=""></option>' + str;
					$('#selDistrict').html(str);
					$('#selDistrict').val("");
					
					var pid = $('#selDistrict').val();
					if (pid != "") {
						$.doPostGetLocationList(pid, '#selWard', url);
					} else {
						$('#selWard').find('option').remove();
					}
				}
			);
		});
		
		$('#selDistrict').change(function() {				
			url = 'index.php?location&action=get';
			var pid = $('#selDistrict').val();
			if (pid != "") {
				$.post(url, 
					{parentID: pid}, 
					function(xml) {
						var str = $.getXMLStringOf(xml, 'location');
						str = '<option value=""></option>' + str;
						$('#selWard').html(str);
						$('#selWard').val("");
					}
				);
			}
		});
		
		var url = 'index.php?location&action=get';
		var pid = 0;			
		$.post(url,{parentID: pid},function(xml) {
			var str1 = $.getXMLStringOf(xml, 'location');
			if (str1 != '') {
				$('#selCity').html(str1);
			}
		});
	}*/
});

$(document).ready(function(){
	if ($("#dlgSendMessage").length > 0) {
		$('#dlgSendMessage').dialog({autoOpen: false, width:'380px'});
		
		$('#frmSendMess').submit(function() {
			var url = "index.php?send&type=message";
			var mess = $('#frmSendMess textarea[name=mess]').val();
			var receiverId = $('#frmSendMess input[name=receiver]').val();
			var title = $('#frmSendMess input[name=title]').val();		
			
			if (receiverId && $.trim(mess) != '') {
				$.post(url, {receiverId:receiverId, mess:mess, title:title}, function(data){
					if (data) {
						$('#frmSendMess textarea[name=mess]').val('');
						$('#frmSendMess input[name=title]').val('');
						$('#dlgSendMessage').dialog('close');	
					} 
					return false;
				});
			}
			return false;
		});
	}
});